;
;	>> PigXLs - Stage 3 <<
;
;	A 128 bytes intro for the Atari 800 XL (c) 2010-09-12 by JAC!
;	Stage 3: Lores mode with stack/PLA adressing and scaled coordinates, color based on coordinates and $d20x alarm sound
;
;	Created using WUDSN IDE. Visit http://www.wudsn.com to increase my hit counter.

;	IOCB commands
open	= $03
close	= $0c
plot	= $09
draw	= $11
fill	= $12

iocom	= $342	;Command
ioadr	= $344	;Address
icaux1	= $034A	;Auxilary 1
icaux2	= $034B	;Auxilary 2
ciov	= $e456	;CIO vector

rowcrs	= $54	;Row of cursor, 1 byte
colcrs	= $55	;Column of cursor, 2 bytes

color	= $2fb	;Color for graphics operations

*	= $154	;Start at start position "S"=$53

;	These are the x,y coordinates for the lines.
;	Bit 0 in the x coordinate is also the line color.
;	The first line is black because is implicitly starts at 0,0.
;	The last relevant coordinate must be the same as the first, except for the color.
;	The coordinates are chosen in a way they represent valid code.
;	This allows the demo to start without having a RUNADR segment. 
;	.byte   x,   y,   x,   y,   x,   y,   x,   y,   x,   y,   x,   y,   x,   y
pigxy	.byte $18, $43, $21, $3E, $5d, $4E, $61, $58, $69, $5A, $71, $4E, $75, $55
	.byte $7f, $57, $8D, $35, $75, $15, $4F, $1D, $45, $15, $49, $1F, $45, $23
	.byte $2d, $19, $3b, $26, $37, $2D, $23, $34, $17, $2c, $17, $43

start
	ldx #'S		;Instead of string definition "S:",$9B, causes also invisible line.
 	stx $00		;Operand $00 will terminate dodraw
 	txs		;X=$53 => PLA will start at $154
	ldx #$60	;Channel 6
	lda #open	;Set open command
	sta iocom,x
	
	lda #$06	;Graphics 6, 2 colors
	sta icaux2,x	;icaus1,x is already 0
loop 	jsr ciov	;Leaves a and x unchanged, returns y=1
	lda #draw	;Set draw command
	sta iocom,x
dodraw 	pla
	sta colcrs
 	sta color	;Bit 0 of the xpos is the color
 	pla
 	sta rowcrs
	bne loop	;Will end when PLA has reached "stx $00".

effloop
	lda 20
	tax
	eor 19
	sta $d200

effloopx
	txa
	and #31
	cmp #16
	bcc *+4
	eor #31
	sta $d40a
	sta $d016

	ora #$a0
	sta $d201

	lda $d40b
	beq effloop
	asl
	bit $76		;DELTAR, will be $10 after the last line 
	beq *+4
	eor #$0f
	sta $d01a
	inx
	bvc effloopx

